﻿using dotnetcore_Demo.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace dotnetcore_Demo.Controllers
{
    public class HomeController : Controller
    {
        private IClock clock;
        private readonly IHubContext<CountHub> _hubContext;

        public HomeController(IClock _clock,IHubContext<CountHub> hubContext)
        {
            clock = _clock;
            _hubContext = hubContext;
            //string date = clock.say();
            //Console.WriteLine(date);
        }

        public ActionResult Index()
        {
            return new ContentResult() { Content = clock.say() };
        }

        [Route("api/count")]
        [HttpPost]
        public async Task<IActionResult> Post()
        {
            var connectionId = _hubContext.Clients;
            await _hubContext.Clients.All.SendAsync("someFunc",new { name="asas"});
            return Accepted(1);
        }
    }
}
